package trab4.transactions.two_phase_commit;

import sim.core.* ;

import trab4.rpc.*;
import trab4.transactions.two_phase_commit.rpc_msgs.*;

public class Client_2PC_Stub extends ClientTransactionStub implements TwoPhaseCommit {
	
	
	public Client_2PC_Stub( EndPoint client, EndPoint server ) {	
		super( client, server ) ;
		this.client = client ;
		this.server = server ;
	}

	public void tpc_op1() {
		TcpChannel ch = client.tcpSend( server, new Msg_2PC_OP1() ) ;
		if( ch == null ) throw new RemoteException("send failed. node is offline...") ;
		ch.tcpRead() ;
	}

	public <T> T tpc_op2() {
		TcpChannel ch = client.tcpSend( server, new Msg_2PC_OP2() ) ;
		if( ch == null ) throw new RemoteException("send failed. node is offline...") ;
		Msg_2PC_Return res = ch.tcpRead() ;
		return res.value()  ;
	}
}
